#ifndef XGE_GRAPHICS_SCENE_MGR_H_
#define XGE_GRAPHICS_SCENE_MGR_H_
#include "xge_common_config.h"
#include "xtimer.h"
#include "node_basenode.h"

#include "xmainloop.h"


namespace xge{

  class XGameEngine;
  class MainLoop;

namespace graphics{

  class RootNode;
  using xge_internal::Timer;

  // The scene manager will be created by the XGameEngine , it is the
  // manager to manage all the RenderingNode derived class, it force 
  // the function of the certain node will be updated during the frame
  // callback in the game engine ! All the operation is using RootNode
  // since , all the node is the child node of the RootNode , the
  // scene manager will take the charge of creating and destroying the
  // RootNode .
  class SceneManager {
  public:
    // The scene manager has only one function , and every scene node
    // will be started from the root node , so the scene manager is 
    // simply take care of the root node and return this root node .
    // When the user gets the root node , the root node will provide
    // every kinds of method to do the rendering management and node
    // management !
    RootNode* GetRootNode() const {
      return root_;
    }
  public: 
    // The following function allows you to setting up the FPS of the
    // SceneManager , which means how many OnPaint Message will spawn
    // in a second 
    void   SetFPS( size_t fps ) {
      fps_value_ = fps;
      fps_per_tick_ = (Timer::tick_t)(1000/fps);
    }
    size_t GetFPS() const {
      return fps_value_;
    }
  private:
    // This function will spawn the OnPaint message
    void Loop( const Timer::tick_t& time_diff );
    // This class will only be initialized by the XGameEngine class
    // it is a totally private class , so we hide its Ctor and Dtor
    SceneManager() ;
    ~SceneManager();
  private:
    // RootNode node for the whole scene manager 
    RootNode* root_ ;
    friend class XGameEngine;
    friend class MainLoop;
    // Using the following two value to control the
    // ticking in the game !
    size_t fps_value_;
    Timer::tick_t fps_per_tick_;
    Timer::tick_t cur_time_;
  };

}// namespace graphics
}// namespace xge 

#endif// XGE_GRAPHICS_SCENE_MGR_H_